package servlet;

import dao.BooksDao;
import dao.impl.BooksDaoImpl;
import service.impl.BookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class DelBookServlet extends HttpServlet{
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int bID = Integer.parseInt(request.getParameter("bID"));
        BooksDao booksDao = new BooksDaoImpl();
        BookServiceImpl bookService = new BookServiceImpl();
        bookService.setBooksDao(booksDao);

        int res = bookService.delBookbyID(bID);

        if (res > 0){
            request.setAttribute("msg","书籍"+bID+"删除成功");
        }else {
            request.setAttribute("msg","删除失败");
        }
        request.getRequestDispatcher("BookServlet").forward(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
